package com.emmmya.ocs.modules.system.controller;

import com.emmmya.ocs.common.utils.JwtUtils;
import com.emmmya.ocs.common.vo.Result;
import com.emmmya.ocs.config.redis.SystemCacheRedisManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @description:
 * @author: 咕噜肉IT小店-黑医
 * @createDate: 2020-11-11
 * @version: 1.0
 */
@RequestMapping("redis")
@Controller
public class RedisController {
    @Autowired
    SystemCacheRedisManager redisManager;

    @Autowired
    JwtUtils jwtUtils;


    @RequestMapping("getAll")
    @ResponseBody
    public Result<Object> getAll(){
        return null;
    }

    @RequestMapping("get/{key}")
    @ResponseBody
    //@OperateLog(value="根据key查询value",module = "redis管理模块")
    public String getKey(@PathVariable("key") String key){
        Object o = redisManager.get(key);
        if(o != null) {
           // System.out.println(jwtUtils.getUsername(o.toString()));
            return o.toString();
        }
        return "查询的key不存在缓存";
    }

    @RequestMapping("getExpire/{key}")
    @ResponseBody
    //@OperateLog(value="根据key查询过期时间",module = "redis管理模块")
    public String getKeyExpire(@PathVariable("key") String key){
        Long time = redisManager.getExpire(key);
        Date date = new Date(time);
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
    }
}
